<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of ReadFiles</title>
  <meta name="keywords" content="ReadFiles">
  <meta name="description" content="% Read in multiple ASCII .TXT Files">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2005 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../../m2html.css">
  <script type="text/javascript">
    if (top.frames.length == 0) { top.location = "../../index.html"; };
  </script>
</head>
<body>
<a name="_top"></a>
<!-- ../menu.html trunk --><!-- menu.html utils -->
<h1>ReadFiles
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>% Read in multiple ASCII .TXT Files</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>This is a script file. </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre class="comment">% Read in multiple ASCII .TXT Files
 This program reads in multiple ASCII text files into a single structure.</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="tfile.html" class="code" title="function [A]=tfile(fullName,screenData,ignoreBS);">tfile</a>	tfile reads the data from an RDI ASCII output file and puts the</li></ul>
This function is called by:
<ul style="list-style-image:url(../../matlabicon.gif)">
</ul>
<!-- crossreference -->



<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre>0001 <span class="comment">%% Read in multiple ASCII .TXT Files</span>
0002 <span class="comment">% This program reads in multiple ASCII text files into a single structure.</span>
0003 
0004 <span class="comment">% August 5, 2008</span>
0005 <span class="comment">% Jon Czuba</span>
0006 <span class="comment">% USGS - Illinois Water Science Center</span>
0007 
0008 <span class="comment">%% Determine Files to Process</span>
0009 <span class="comment">% Prompt user for directory containing files</span>
0010 zPathName = uigetdir;
0011 Files = dir(zPathName);
0012 allFiles = {Files.name};
0013 filefind=strfind(allFiles,<span class="string">'ASC.TXT'</span>)';
0014 filesidx=nan(size(filefind,1),1);
0015 <span class="keyword">for</span> i=1:size(filefind,1)
0016     filesidx(i,1)=size(filefind{i},1);
0017 <span class="keyword">end</span>
0018 filesidx=find(filesidx&gt;0);
0019 files=allFiles(filesidx);
0020 
0021 <span class="comment">% Allow user to select which files are to be processed</span>
0022 selection = listdlg(<span class="string">'ListSize'</span>,[300 300],<span class="string">'ListString'</span>, files);
0023 zFileName = files(selection);
0024 
0025 <span class="comment">% Determine number of files to be processed</span>
0026 <span class="keyword">if</span>  isa(zFileName,<span class="string">'cell'</span>)
0027     z=size(zFileName,2);
0028     zFileName=sort(zFileName);       
0029 <span class="keyword">else</span>
0030     z=1;
0031     zFileName={zFileName}
0032 <span class="keyword">end</span>
0033 
0034 <span class="comment">%% Read in Selected Files</span>
0035 <span class="comment">% Initialize row counter</span>
0036 j=0;
0037 st=[<span class="string">'A'</span>; <span class="string">'B'</span>; <span class="string">'C'</span>; <span class="string">'D'</span>; <span class="string">'E'</span>; <span class="string">'F'</span>];
0038 <span class="comment">% Begin master loop</span>
0039 <span class="keyword">for</span> zi=1:z
0040     <span class="comment">% Open txt data file</span>
0041     <span class="keyword">if</span>  isa(zFileName,<span class="string">'cell'</span>)
0042         fileName=strcat(zPathName,<span class="string">'\'</span>,zFileName(zi));
0043         fileName=char(fileName);
0044     <span class="keyword">else</span>
0045         fileName=strcat(zPathName,zFileName);
0046     <span class="keyword">end</span>
0047 
0048     <span class="comment">% screenData 0 leaves bad data as -32768, 1 converts to NaN</span>
0049     screenData=1;
0050 
0051     <span class="comment">% tfile reads the data from an RDI ASCII output file and puts the</span>
0052     <span class="comment">% data in a Matlab data structure with major groups of:</span>
0053     <span class="comment">% Sup - supporing data</span>
0054     <span class="comment">% Wat - water data</span>
0055     <span class="comment">% Nav - navigation data including GPS.</span>
0056     <span class="comment">% Sensor - Sensor data</span>
0057     <span class="comment">% Q - discharge related data</span>
0058     ignoreBS = 0;
0059     [A(zi)]=<a href="tfile.html" class="code" title="function [A]=tfile(fullName,screenData,ignoreBS);">tfile</a>(fileName,screenData,ignoreBS);
0060 
0061 <span class="keyword">end</span>
0062 
0063 <span class="comment">%% Save data returned by tfile to .mat with same prefix as ASCII</span>
0064 idx=strfind(zFileName,<span class="string">'_'</span>);
0065 namecut=zFileName{1}(1:idx{1}(1)-1);
0066 numcut1=zFileName{1}(idx{1}(3)-2:idx{1}(3)-1);
0067 numcut2=zFileName{z}(idx{z}(3)-2:idx{z}(3)-1);
0068 savefile=strcat(namecut,<span class="string">'_'</span>,numcut1,<span class="string">'_'</span>,numcut2,<span class="string">'.mat'</span>);
0069 save(savefile, <span class="string">'A'</span>,<span class="string">'z'</span>)
0070 
0071 <span class="comment">%% Clear Unwanted Variables</span>
0072 
0073 clear Files allFiles fileName filefind files filesidx i j screenData selection<span class="keyword">...</span>
0074     st zPathName zi idx namecut numcut1 numcut2</pre></div>
<hr><address>Generated on Wed 04-Jun-2014 14:21:02 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" target="_parent">m2html</a></strong> &copy; 2005</address>
</body>
</html>